import {
  getMaintainNodeList,
  getEquipmentList,
  DeleteEquipment,
  AddEquipment,
  EditEquipment,
} from '@/services/municipal';

export default {
  namespace: 'repair',
  state: {
    wxglList: [],
    MaintainNodeList: [],
  },

  effects: {
    //维修流程
    *fetchMaintainNode({ payload, callback }, { call, put }) {
      const response = yield call(getMaintainNodeList, payload);

      if (!response.ErrorMessage) {
        yield put({
          type: 'queryMaintainNode',
          payload: response.Data.MaintainNode,
        });
      } else {
        if (callback) callback(response);
      }
    },
    //维修设施清单
    *fetchEquipmentList({ payload, callback }, { call, put }) {
      const response = yield call(getEquipmentList, payload);

      if (!response.ErrorMessage) {
        yield put({
          type: 'queryEquipmentList',
          payload: response.Data.EquipmentDicList,
        });
      } else {
        if (callback) callback(response);
      }
    },
    //删除维修设施
    *fetchDeleteEquipment({ payload, callback }, { call, put }) {
      const response = yield call(DeleteEquipment, payload);
      if (callback) callback(response);
    },
    //新增维修设施
    *fetchAddEquipment({ payload, callback }, { call, put }) {
      const response = yield call(AddEquipment, payload);
      if (callback) callback(response);
    },
    //编辑维修设施
    *fetchEditEquipment({ payload, callback }, { call, put }) {
      const response = yield call(EditEquipment, payload);
      if (callback) callback(response);
    },
  },

  reducers: {
    //维修流程
    queryMaintainNode(state, action) {
      return {
        ...state,
        MaintainNodeList: action.payload,
      };
    },
    //维修设施清单
    queryEquipmentList(state, action) {
      return {
        ...state,
        wxglList: action.payload,
      };
    },
  },
};
